<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文章管理 - 学生知识管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: #f5f5f5;
            line-height: 1.6;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1rem 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .nav {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 2rem;
        }
        
        .logo {
            font-size: 1.5rem;
            font-weight: bold;
        }
        
        .nav-links {
            display: flex;
            list-style: none;
            gap: 2rem;
        }
        
        .nav-links a {
            color: white;
            text-decoration: none;
            transition: opacity 0.3s;
        }
        
        .nav-links a:hover {
            opacity: 0.8;
        }
        
        .container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 2rem;
        }
        
        .page-header {
            background: white;
            padding: 2rem;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .page-title {
            font-size: 1.8rem;
            color: #333;
        }
        
        .btn {
            padding: 0.75rem 1.5rem;
            border: none;
            border-radius: 5px;
            font-size: 1rem;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            transition: background 0.3s;
        }
        
        .btn-primary {
            background: #667eea;
            color: white;
        }
        
        .btn-primary:hover {
            background: #5a6fd8;
        }
        
        .btn-secondary {
            background: #6c757d;
            color: white;
        }
        
        .btn-secondary:hover {
            background: #5a6268;
        }
        
        .btn-danger {
            background: #dc3545;
            color: white;
        }
        
        .btn-danger:hover {
            background: #c82333;
        }
        
        .btn-sm {
            padding: 0.5rem 1rem;
            font-size: 0.875rem;
        }
        
        .filters {
            background: white;
            padding: 1.5rem;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
        }
        
        .filter-row {
            display: flex;
            gap: 1rem;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .filter-group {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }
        
        .filter-group label {
            font-weight: 500;
            color: #333;
        }
        
        .filter-group select,
        .filter-group input {
            padding: 0.5rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        
        .articles-grid {
            display: grid;
            gap: 1.5rem;
        }
        
        .article-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
            transition: transform 0.3s, box-shadow 0.3s;
        }
        
        .article-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 20px rgba(0,0,0,0.15);
        }
        
        .article-content {
            padding: 1.5rem;
        }
        
        .article-meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
            font-size: 0.875rem;
            color: #666;
        }
        
        .article-status {
            padding: 0.25rem 0.75rem;
            border-radius: 15px;
            font-size: 0.75rem;
            font-weight: 500;
        }
        
        .status-published {
            background: #d4edda;
            color: #155724;
        }
        
        .status-draft {
            background: #fff3cd;
            color: #856404;
        }
        
        .status-archived {
            background: #f8d7da;
            color: #721c24;
        }
        
        .article-title {
            font-size: 1.25rem;
            font-weight: 600;
            color: #333;
            margin-bottom: 0.5rem;
            line-height: 1.4;
        }
        
        .article-title a {
            color: inherit;
            text-decoration: none;
        }
        
        .article-title a:hover {
            color: #667eea;
        }
        
        .article-summary {
            color: #666;
            margin-bottom: 1rem;
            line-height: 1.5;
        }
        
        .article-stats {
            display: flex;
            gap: 1rem;
            margin-bottom: 1rem;
            font-size: 0.875rem;
            color: #666;
        }
        
        .stat-item {
            display: flex;
            align-items: center;
            gap: 0.25rem;
        }
        
        .article-actions {
            display: flex;
            gap: 0.5rem;
            justify-content: flex-end;
        }
        
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 0.5rem;
            margin-top: 2rem;
        }
        
        .pagination a,
        .pagination span {
            padding: 0.5rem 1rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            text-decoration: none;
            color: #333;
        }
        
        .pagination a:hover {
            background: #667eea;
            color: white;
            border-color: #667eea;
        }
        
        .pagination .current {
            background: #667eea;
            color: white;
            border-color: #667eea;
        }
        
        .empty-state {
            text-align: center;
            padding: 3rem;
            color: #666;
        }
        
        .empty-state h3 {
            margin-bottom: 1rem;
            color: #333;
        }
        
        @media (max-width: 768px) {
            .page-header {
                flex-direction: column;
                gap: 1rem;
                text-align: center;
            }
            
            .filter-row {
                flex-direction: column;
                align-items: stretch;
            }
            
            .article-actions {
                justify-content: center;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <nav class="nav">
            <div class="logo">🎓 学生知识管理系统</div>
            <ul class="nav-links">
                <li><a href="/">首页</a></li>
                <li><a href="/articles">文章</a></li>
                <li><a href="/categories">分类</a></li>
                <li sec:authorize="hasRole('ADMIN')"><a href="/admin/articles">文章管理</a></li>
                <li><a href="/profile">个人中心</a></li>
                <li><a href="/logout">退出</a></li>
            </ul>
        </nav>
    </header>
    
    <div class="container">
        <!-- 成功消息显示 -->
        <div th:if="${param.success}" class="alert alert-success" style="margin-bottom: 20px; padding: 15px; background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724;">
            <span th:text="${param.message}">操作成功！</span>
        </div>
        
        <div class="page-header">
            <h1 class="page-title">文章管理</h1>
            <a href="/articles/create" class="btn btn-primary">📝 写文章</a>
        </div>
        
        <div class="filters">
            <form method="get" action="/articles">
                <div class="filter-row">
                    <div class="filter-group">
                        <label for="status">状态</label>
                        <select id="status" name="status">
                            <option value="" th:selected="${param.status == null}">全部</option>
                            <option value="PUBLISHED" th:selected="${param.status == 'PUBLISHED'}">已发布</option>
                            <option value="DRAFT" th:selected="${param.status == 'DRAFT'}">草稿</option>
                            <option value="ARCHIVED" th:selected="${param.status == 'ARCHIVED'}">已归档</option>
                        </select>
                    </div>
                    
                    <div class="filter-group">
                        <label for="category">分类</label>
                        <select id="category" name="categoryId">
                            <option value="" th:selected="${param.categoryId == null}">全部分类</option>
                            <option th:each="category : ${categories}" 
                                    th:value="${category.id}" 
                                    th:text="${category.name}"
                                    th:selected="${param.categoryId == category.id.toString()}">分类名</option>
                        </select>
                    </div>
                    
                    <div class="filter-group">
                        <label for="keyword">关键词</label>
                        <input type="text" id="keyword" name="keyword" 
                               th:value="${param.keyword}" placeholder="搜索标题或内容">
                    </div>
                    
                    <div class="filter-group">
                        <label>&nbsp;</label>
                        <button type="submit" class="btn btn-primary">🔍 搜索</button>
                    </div>
                </div>
            </form>
        </div>
        
        <div class="articles-grid" th:if="${articles != null and articles.hasContent()}">
            <div class="article-card" th:each="article : ${articles.content}">
                <div class="article-content">
                    <div class="article-meta">
                        <span th:text="${#temporals.format(article.createdAt, 'yyyy-MM-dd HH:mm')}">2024-01-01 12:00</span>
                        <span class="article-status" 
                              th:classappend="'status-' + ${article.status.name().toLowerCase()}"
                              th:text="${article.status == T(com.example.studentknowledge.entity.Article.Status).PUBLISHED ? '已发布' : 
                                        article.status == T(com.example.studentknowledge.entity.Article.Status).DRAFT ? '草稿' : '已归档'}">状态</span>
                    </div>
                    
                    <h3 class="article-title">
                        <a th:href="@{/articles/{id}(id=${article.id})}" th:text="${article.title}">文章标题</a>
                    </h3>
                    
                    <p class="article-summary" th:text="${article.summary}">文章摘要...</p>
                    
                    <div class="article-stats">
                        <span class="stat-item">
                            👁️ <span th:text="${article.viewCount}">0</span>
                        </span>
                        <span class="stat-item">
                            👍 <span th:text="${article.likeCount}">0</span>
                        </span>
                        <span class="stat-item">
                            💬 <span th:text="${article.commentCount}">0</span>
                        </span>
                        <span class="stat-item">
                            ❤️ <span th:text="${article.favoriteCount}">0</span>
                        </span>
                        <span class="stat-item">
                            ⭐ <span th:text="${article.points}">0</span> 积分
                        </span>
                    </div>
                    
                    <div class="article-actions">
                        <a th:href="@{/articles/{id}(id=${article.id})}" class="btn btn-sm btn-outline-primary">查看文章</a>
                        <a th:href="@{/articles/{id}/edit(id=${article.id})}" class="btn btn-sm btn-outline-secondary">编辑</a>
                        <a th:href="@{/articles/{id}/delete(id=${article.id})}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定要删除这篇文章吗？')">删除</a>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="empty-state" th:if="${articles == null or !articles.hasContent()}">
            <h3>📝 还没有文章</h3>
            <p>开始写你的第一篇文章吧！</p>
            <a href="/articles/create" class="btn btn-primary">立即创建</a>
        </div>
        
        <!-- 分页 -->
        <div class="pagination" th:if="${articles != null and articles.totalPages > 1}">
            <a th:if="${articles.hasPrevious()}" 
               th:href="@{/articles(page=${articles.number - 1}, size=${articles.size}, status=${param.status}, categoryId=${param.categoryId}, keyword=${param.keyword})}">上一页</a>
            
            <span th:each="i : ${#numbers.sequence(0, articles.totalPages - 1)}">
                <a th:if="${i != articles.number}" 
                   th:href="@{/articles(page=${i}, size=${articles.size}, status=${param.status}, categoryId=${param.categoryId}, keyword=${param.keyword})}"
                   th:text="${i + 1}">1</a>
                <span th:if="${i == articles.number}" class="current" th:text="${i + 1}">1</span>
            </span>
            
            <a th:if="${articles.hasNext()}" 
               th:href="@{/articles(page=${articles.number + 1}, size=${articles.size}, status=${param.status}, categoryId=${param.categoryId}, keyword=${param.keyword})}">下一页</a>
        </div>
    </div>
</body>
</html>